package common;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import interfaces.Model;

public class ModelComposite implements Model {

	private List<Model> modelList;
	
	public void initialize(Properties properties) {
		String [] modelNames = properties.getProperty("model_names").split(" ");
		modelList = new ArrayList<Model>(modelNames.length);
		for(String modelName : modelNames) {
			modelList.add(ModelFactory.getModel(modelName));
		}
	}
	
	@Override
	public void train(List<String> data) {
		for(Model model : modelList) {
			model.train(data);
		}
	}

	@Override
	public List<Double> test(List<String> data) {
		return modelList.get(0).test(data);
	}

	@Override
	public void write(String filename) {
		for(Model model : modelList) {
			model.write(filename);
		}
	}

	@Override
	public void read(String filename) {
		for(Model model : modelList) {
			model.read(filename);
		}
	}

	@Override
	public String getName() {
		return "composite";
	}

}
